#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
struct node{
    int d,v,x;
};
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        int n,m,L,V;
        cin>>n>>m>>L>>V;
        node a[101010]={};
        int b[101010]={};
        int ans=0,o=0,c=0;
        for(int i=1;i<=n;i++){
            cin>>a[i].d>>a[i].v>>a[i].x;
            if(a[i].v>V&&a[i].x==0){
                ans++;
            }
            if(a[i].x==0){
                o++;
            }else if(a[i].x>0){
                c++;
            }
        }
        for(int i=1;i<=m;i++){
            cin>>b[i];
        }
        sort(b+1,b+n+1);
        if(o==n){
            cout<<ans<<" "<<m-1<<"\n";
        }
    }
    return 0;
}
